package com.yuheadline.media.controller;

import com.dust.yuheadline.common.utils.PageResult;
import com.dust.yuheadline.common.utils.Result;
import com.yuheadline.media.service.MaterialService;
import com.yuheadline.model.media.domain.MaterialImage;
import com.yuheadline.model.media.dto.MaterialPageQueryDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 素材管理
 *
 * @author 高翔宇
 * @since 2024/5/1 周三 下午9:57
 */
@Slf4j
@RestController
@RequestMapping("/api/media/material")
@RequiredArgsConstructor
@Tag(name = "素材管理接口")
public class MaterialController {
    private final MaterialService materialService;

    /**
     * 分页查询当前用户的素材列表
     */
    @PostMapping("/pageList")
    @Operation(summary = "分页查询当前用户的素材列表")
    public PageResult<List<MaterialImage>> pageList(@RequestBody MaterialPageQueryDto materialPageQueryDto) {
        log.info("分页查询当前用户的素材列表：{}", materialPageQueryDto);
        return materialService.pageList(materialPageQueryDto);
    }

    /**
     * 上传素材
     */
    @PostMapping("/upload")
    @Operation(summary = "上传素材")
    public Result<?> upload(@RequestParam("material") @Validated MultipartFile file) {
        log.info("上传素材...");
        return materialService.upload(file);
    }

    /**
     * 根据id删除素材
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "根据id删除素材")
    public Result<?> deleteById(@PathVariable Long id) {
        log.info("根据id删除素材：{}", id);
        return materialService.deleteById(id);
    }
}
